package com.core.reach.cloudhub.service.impl;

import com.core.reach.cloudhub.dao.StorageMapper;
import com.core.reach.cloudhub.service.StorageService;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author ga.zhang
 * @version V1.0
 * @description: TODO
 * @date 2020/4/1 15:48
 **/
@Service("storageService")
public class StorageServiceImpl implements StorageService {

    private static final Logger LOGGER = LoggerFactory.getLogger(StorageServiceImpl.class);

    @Resource
    private StorageMapper storageMapper;

    @Override
    public Boolean reduceStorage(Long productId, Integer count) {
        LOGGER.info("------->storage-service中扣减库存开始");
        Boolean isReduce =  storageMapper.reduceStorage(productId, count) > 0;
        if (isReduce) {
            LOGGER.info("------->storage-service中扣减库存成功");
        } else {
            LOGGER.info("------->storage-service中扣减库存失败");
        }
        return isReduce;
    }
}
